package com.cms.framework;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import com.cms.exception.ExceptionLog;
import com.cms.facade.RequestFacade;
import com.cms.facade.SessionFacade;
public class CommandException extends Exception {

	private final static Logger logger = Logger.getLogger(CommandException.class);

	public CommandException() {
		super();

		ExceptionLog.getInstance().recodeException(this, "", "");
	}

	public CommandException(Exception e) {
		super(e);
		// e.printStackTrace();
		logger.debug(e.getMessage());

		ExceptionLog.getInstance().recodeException(this, "", "");
	}

	public CommandException(String msg) {
		super(msg);
		logger.debug(msg);

		ExceptionLog.getInstance().recodeException(this, "", "");
	}

	public CommandException(HttpServletRequest req, Exception e) {
		// super(e.getMessage());
		e.printStackTrace();
		logger.error(e.getMessage(), e);
		RequestFacade.setSuccessFlag(req, Boolean.FALSE);

	    RequestFacade.setErrorMsg(req, e.getMessage());

		RequestFacade.setExceptionInfo(req, ExceptionLog.getInstance().recodeException(this, SessionFacade.getUser(req.getSession()), ""));
	}

	public CommandException(HttpServletRequest req, String msg) {
		super(msg);
		RequestFacade.setSuccessFlag(req, Boolean.FALSE);

		RequestFacade.setErrorMsg(req, msg);

		RequestFacade.setExceptionInfo(req, ExceptionLog.getInstance().recodeException(this, SessionFacade.getUser(req.getSession()), ""));
	}

}
